/*
 * AbstractController.java
 *
 * Created on January 22, 2007, 8:41 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package controller;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import java.util.LinkedList;
import view.AbstractViewPanel;

/**
 * This class provides base level functionality for each controller. This includes the
 * ability to register multiple models and views, propagating model change events to
 * each of the views, and providing a utility function to broadcast model property
 * changes when necessary.

 */
public abstract class AbstractController implements PropertyChangeListener {

    private LinkedList<AbstractViewPanel> registeredViews;

    /** Creates a new instance of Controller */
    public AbstractController() {
        registeredViews = new LinkedList<AbstractViewPanel>();

    }

    public void addView(AbstractViewPanel view) {
        registeredViews.add(view);
    }

    public void removeView(AbstractViewPanel view) {
        registeredViews.remove(view);
    }

    public void propertyChange(PropertyChangeEvent evt) {

        for (AbstractViewPanel view : registeredViews) {
            view.modelPropertyChange(evt);
        }
    }
}
